/*
 *  message_dispatcher.cpp
 */

#include <string>
#include <vector>
#include "debug.h"
#include "lock.h"
#include "message.h"
#include "message_dispatcher.h"
#include "protocol.h"
#include "session.h"
#include "socket.h"
#include "socket_exception.h"

MessageDispatcher::MessageDispatcher(Session* session) : q() {
    this->session = session;
}

MessageDispatcher::~MessageDispatcher() {}

void MessageDispatcher::run() {
    while (session->isAlive()) {
        while (!q.empty()) {
            Message* msg = q.pop();
            session->getProtocol().sendMessage(msg, *(session->getSocket()));
            delete msg;
        }
    }
}

void MessageDispatcher::send(Message* msg) {
    q.push(msg);
}

//{+}

